//
//  ZJNavViewController.swift
//  BuildOnline
//
//  Created by ywy on 2018/3/1.
//  Copyright © 2018年 Wely. All rights reserved.
//

import UIKit

class ZJNavViewController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = nil
//        initNavBar()
        // Do any additional setup after loading the view.
    }
//    func initNavBar() {
//        let navBar = UINavigationBar.appearance()
//        //       navBar.setBackgroundImage(UIImage.init(named: "navigationbarbg_White"), for: .default)
//        //
//        //        let item = UIBarButtonItem.appearance()
//        //        item.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.gray], for: .normal)
//    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.childViewControllers.count > 0 {
            
            let button = UIButton(type: .system)
            button.setImage(UIImage.init(named: "navigationButtonReturn")?.withRenderingMode(.alwaysOriginal), for: .normal)
            button.frame = ZCGRECT(x: 0, y: 0, width: 20, height: 20)
            //            button.backgroundColor = UIColor.red
            //            button.contentEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0)
            let view = UIView() // 解决点击区域过大
            view.frame = ZCGRECT(x: 0, y: StatusHeight, width: 20, height: 20)
            view.addSubview(button)
            button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: view)
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
    @objc func buttonAction() {
        self.popViewController(animated: true)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
